/*
 * Arena.h
 *
 *  Created on: Nov 11, 2010
 *      Author: dhovemey
 */

#ifndef ARENA_H_
#define ARENA_H_

#include <cstddef>
#include "runtime/Object.h"
class VirtualMachine;
class Arena;

class ArenaIterator {
private:
	VirtualMachine *m_vm;
	Arena *m_arena;
	char *m_ptr;

	ArenaIterator(const ArenaIterator &);
	ArenaIterator& operator=(const ArenaIterator &);

public:
	ArenaIterator(VirtualMachine *vm, Arena *arena);
	virtual ~ArenaIterator();

	bool hasNext() const;
	Object *next();
};

struct Class;

class Arena {
private:
	friend class ArenaIterator;

	VirtualMachine *m_vm;
	char *m_buf;    // base address of allocation memory region
	size_t m_size;  // size of allocation memory region
	char *m_next;   // address of next allocatable block

	Arena(const Arena &);
	Arena& operator=(const Arena &);

public:
	Arena(VirtualMachine *vm, size_t size);
	virtual ~Arena();

	Object *alloc(Class *cls);
	ArenaIterator *iterator();
};

#endif /* ARENA_H_ */
